<template>
  <div>
    <Table
      border
      :columns="columns1"
      :data="favList"
      @on-select="gotoPosting"
    ></Table>
  </div>
</template>

<script>
export default {
  data () {
    return {
      columns1: [
        {
          title: '帖子名',
          key: 'postingName',
          render: (h, params) => {
            let url = '#/Posting/' + params.row.postingId
            return h('a', {
              attrs: {
                href: url,
                target: '_black'
              }
            }, params.row.postingName)
          }
        },
        {
          title: '版块名',
          key: 'boardName',
          render: (h, params) => {
            let url = '#/Board/' + params.row.boardId
            return h('a', {
              attrs: {
                href: url,
                target: '_black'
              }
            }, params.row.boardName)
          }
        },
        {
          title: '收藏日期',
          key: 'collectDate'
        }
      ],
      data1: [
        {
          name: 'John Brown',
          age: 18,
          address: 'New York No. 1 Lake Park',
          date: '2016-10-03'
        },
        {
          name: 'Jim Green',
          age: 24,
          address: 'London No. 1 Lake Park',
          date: '2016-10-01'
        },
        {
          name: 'Joe Black',
          age: 30,
          address: 'Sydney No. 1 Lake Park',
          date: '2016-10-02'
        },
        {
          name: 'Jon Snow',
          age: 26,
          address: 'Ottawa No. 2 Lake Park',
          date: '2016-10-04'
        }
      ],
      // columns1: [
      //   {
      //     title: '版块分区',
      //     key: 'boardName'
      //   },
      //   {
      //     title: '帖子名',
      //     key: 'postingName'
      //   }
      // ],
      favList: []
    }
  },
  methods: {
    gotoPosting: function (row, index) {
      console.log(row)
      console.log(index)
    }
  },
  mounted () {
    var _this = this // 临时变量
    this.$axios({
      method: 'post',
      url: '/login/success'
    }).then(function (response) {
      console.log(response)
      if (!response.data.result) {
        _this.$Message.error('请先登录!')
        _this.$router.push('/loginAuth')
      } else {
        _this.$axios({
          method: 'get',
          url: '/selectFavorite'
        }).then(function (response) {
          console.log(response)
          _this.favList = response.data.result
        })
      }
    })
  }
}
</script>
